home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_100
/
199_01
/
gedio.asm
< prev
next >
Wrap
Assembly Source File
|
1987-12-15
|
29KB
|
1,016 lines
;------------------------------------------------------------------
; Gedio.asm: Screen and keyboard interface routines for the PC
;
; For GED WordStar-like screen editor
; DeSmet C implementation by Mel Tearle - 08/06/86
;
; Microsoft Macroassembler implementation by Michael Yokoyama - 12/06/86
; Revised by Mel Tearle - 07/25/87
;
; data starts here
;------------------------------------------------------------------
_data segment word public 'data'
const segment word public 'const'
const ends
_bss segment word public 'bss'
_bss ends
dgroup group const,_bss,_data
assume cs: _text, ds: dgroup, ss: dgroup, es: dgroup
; In this implementation, all special and function keys are translated
; to the following values.
; control key translations
; control key translations - mapped into cursor-pad.
up_char equ 5 ;arrow up
down_char equ 24 ;arrow down
left_char equ 19 ;arrow left
right_char equ 4 ;arrow right
bol_char equ 15 ;Home
eol_char equ 16 ;End
pageup_char equ 18 ;PgUp
pagedown_char equ 3 ;PgDn
Del_char equ 7 ;Del
; function key definitions
M1 equ 128
M2 equ 129
M3 equ 130
M4 equ 145
M5 equ 132
M6 equ 133
M7 equ 134
M8 equ 135
M9 equ 136
M10 equ 137
; special keys - toggles and keypress
Insert_key equ 138
Caps_Lock_on equ 139
Caps_Lock_off equ 140
Alt_key equ 146
grey_minus equ 142
grey_plus equ 143
; the table that is used to make the translation
; note - not all used
convert db 72, up_char
db 80, down_char
db 75, left_char
db 77, right_char
db 71, bol_char
db 79, eol_char
db 73, pageup_char
db 81, pagedown_char
; db 78, grey_plus
; db 74, grey_minus
db 82, Insert_key
db 83, Del_char
db 59, M1
db 60, M2
db 61, M3
db 62, M4
db 63, M5
db 64, M6
db 65, M7
db 66, M8
db 67, M9
db 68, M10
db 0, 255 ;illegal character
; equates for bios interface.
; the interrupt and codes for the screen interface interrupt.
video equ 10h ;interrupt for dealing with screen
mode equ 0 ;code for setting new screen mode
curtype equ 1 ;code for setting new cursor type
setcur equ 2 ;code for addressing cursor
readcur equ 3 ;code for reading cursor location
readlp equ 4 ;code for reading light pen position
setpage equ 5 ;code to select active page
scrollup equ 6 ;code to scroll screen up
scrolldn equ 7 ;code to scroll screen nown
readch equ 8 ;code to read a character from screen
writeach equ 9 ;code to write char and attributes
writech equ 10 ;code to write character only
setpal equ 11 ;code to set new setpal or border
wdot equ 12 ;code to write a dot
rdot equ 13 ;code to read a dot
wtty equ 14 ;code to write as if teletype
state equ 15 ;code to find current screen status
; used in set_video
mono_adr equ 0b000h ;mono adapter
graph_adr equ 0b800h ;graphics adapter*
vadrs dw 0
; the interrupt and codes for the keyboard interface.
keyboard equ 16h ;interrupt 16 to deal with keyboard
cicode equ 0 ;code for reading a character
cstscode equ 1 ;reports if character is ready
kbstatus equ 2 ;get keyboard status - shifts, caplocks
kbset db 0
; caution: must change column number if 40 column mode
crt_cols equ 80
; Note: 25 for MS-DOS, 24 for CP/M as cp/m steals the bottom line.
_scr_rows dw 24 ; current number of rows, for ged, was 25
_scr_cols dw crt_cols ; current number of columns
_scr_mode db 0 ; current screen mode
_scr_page db 0 ; current page
_scr_attr db 7 ; current attributes for screen
; 7 is white letters on black
_scr_window_top db 1 ; first line to scroll, was 0
_data ends
;------------------------------------------------------------------
; code starts here
;------------------------------------------------------------------
_text segment byte public 'code'
assume cs:_text
; Variables available to C programs
public _scr_cols, _scr_rows, _scr_xy, _scr_clr
public _scr_mode, _scr_page, _scr_attr, _scr_window_top
public _scr_setup, _scr_term, _scr_csts, _scr_setmode
public _scr_clrl, _scr_cls, _scr_scup, _scr_scrup
public _scr_scrdn, _scr_co, _scr_ci, _get_graphic
public _scr_sinp, _scr_cursoff, _scr_curson, _scr_mark
public _scr_putch, _scr_delete, _get_mode, _calc_video
public _scr_putstr, _scr_aputch, _get_kbstat, _caps_on
public _scr_scdn, _scr_aputs, _set_video
;-------------------------------------------------------------------------
; _scr_setup Call _scr_setup before using any other routine unless the
; starting mode is 80X25 character mode (3,4, or 7).
; This routine must be called for monochrome (mode 7)
; for _scr_curson to set a proper cursor.
;
; Usage: mode = _scr_setup();
;-------------------------------------------------------------------------
_scr_setup proc near
push bp
mov bp, sp
mov ah,state ; get current state
int video
mov _scr_mode, al ; current mode
mov cl,ah ; make cols a word
mov ch,0
mov _scr_cols, cx ; 40 or 80 columns
mov _scr_page, bh
mov _scr_attr, 7 ; set to white chars on black
cmp al, 4 ; see if a character mode
jc got_attr
cmp al, 7 ; 7 is for graphics mode
jz got_attr
mov _scr_attr, 0 ; attribute is zero in graphics
got_attr:
mov ah,0 ; return int containing mode
push ax ; slight detour
call _set_video ; get display address
pop ax
pop bp
ret
_scr_setup endp
;-------------------------------------------------------
; _scr_term Do any required termination.
;
; Usage: _scr_term();
;-------------------------------------------------------
_scr_term proc near
ret
_scr_term endp
;-------------------------------------------------------
; _scr_setmode Set a new screen mode.
;
; Usage: _scr_setmode(new mode);
;-------------------------------------------------------
_scr_setmode proc near
push bp
mov bp, sp
mov al, [bp+4] ; new mode value
mov ah, mode
int video ; set new mode
call _scr_setup ; remember new values
pop bp
ret
_scr_setmode endp
;-------------------------------------------------------
; _scr_xy Sets cursor at any location.
;
; Usage: _scr_xy( col, row );
;-------------------------------------------------------
_scr_xy proc near
push bp
mov bp, sp
mov dx, [bp+4] ; col
mov ax, [bp+6] ; row
mov dh, al
mov bh, _scr_page ; force page zero
mov ah, setcur ; set cursor location
int video ; call BIOS
pop bp
ret
_scr_xy endp
;-------------------------------------------------------
; _scr_clr Clear entire screen
;
; Usage: _scr_clr();
;-------------------------------------------------------
_scr_clr proc near
push bp
mov bp, sp
mov al, 0 ; ask for a clear window
xor cx, cx ; start at 0,0
mov dh, byte ptr _scr_rows ;last line
dec dh
mov dl, byte ptr _scr_cols ;clear entire width
dec dl ; last column is width-1
mov bh, _scr_attr ; attributes for new bl